﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// membersystem 的摘要说明
/// </summary>
public class membersystem
{
	public membersystem()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    #region 检验用户名

    /// <summary>
    /// 验证用户名在91555或9158数据库里是否存在(-1:9158系统错误,-2:91555系统错误,0:不存在,1;存在)
    /// </summary>
    /// <param name="uid"></param>
    /// <returns>-1:9158系统错误,-2:91555系统错误,0:不存在,1;存在</returns>
    public static int IsExistUidAll(string uid)
    {
       member member = new member();
        int chk_91555 = member.IsExistMemberByGame(uid);
        if (chk_91555 == 0)
        {
            return member.IsExistMember(uid);
        }
        else if (chk_91555 == -1)
            return -2;
        else
            return 1;
    }

    /// <summary>
    /// 91555数据库里是否存在(-1:系统错误 0:不存在 1;存在)
    /// </summary>
    /// <param name="uid"></param>
    /// <returns>-1:系统错误 0:不存在 1;存在</returns>
    public static int IsExistUidByGame(string uid)
    {
        return new member().IsExistMemberByGame(uid);
    }

    /// <summary>
    /// 9158数据库是否存在(-1:系统错误 0:不存在 1;存在)
    /// </summary>
    /// <param name="uid"></param>
    /// <returns>-1:系统错误 0:不存在 1;存在</returns>
    public static int IsExistUid(string uid)
    {
        return new member().IsExistMember(uid);
    }
    #endregion

    #region	用户登录
    /// <summary>
    /// 用户登陆
    /// </summary>
    /// <param name="uid"></param>
    /// <param name="pwd"></param>
    /// <param name="info">用户信息</param>
    /// <returns></returns>
    public static bool MemberLogin(string uid, string pwd, out memberinfo info)
    {
        member member = new member();
        //md5加密
        string Pwd_md5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5").ToLower();
        info = new memberinfo();
        DataRow dr = member.MemberGetInfoByLogin(uid, Pwd_md5);
        if (dr != null)
        {
            info.IDX = Convert.ToInt32(dr["idx"]);
            info.Uid = dr["id"].ToString();
            info.Vip = Convert.ToInt32(dr["isVip"]);
            info.Money = Convert.ToInt64(dr["fortune"]);
            info.Charm = Convert.ToInt32(dr["userML"]);
            return true;
        }
        else
        {
            return false;
        }

        return false;
    }

    #endregion

    #region 用户信息
    /// <summary>
    /// 获得用户信息
    /// </summary>
    /// <param name="uid"></param>
    /// <returns></returns>
    public static memberinfo GetMemberInfo(string uid)
    {
        DataRow dr = new member().GetMemberInfo(uid);

       memberinfo info = new memberinfo();
        if (dr != null)
        {
            info.IDX = Convert.ToInt32(dr["idx"]);
            info.Uid = dr["id"].ToString();
            info.Vip = dr["isVip"] == DBNull.Value ? 0 : Convert.ToInt32(dr["isVip"]);
            info.Money = dr["fortune"] == DBNull.Value ? 0 : Convert.ToInt64(dr["fortune"]);
          //  info.Charm = dr["userML"] == DBNull.Value ? 0 : Convert.ToInt32(dr["userML"]);
            info.NickName = dr["myname"].ToString();
        }

        return info;
    }
    #endregion
}
